package com.atgm.mall.gmmailproduct.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.atgm.mall.gmmailproduct.entity.AttrGroupEntity;
import com.atgm.mall.gmmailproduct.service.AttrGroupService;
import com.atgm.common.utils.PageUtils;
import com.atgm.common.utils.R;



/**
 * 属性分组
 *
 * @author pdx
 * @email 945097967@qq.com
 * @date 2021-08-20 09:07:21
 */
@RestController
@RequestMapping("gmmallproduct/attrgroup")
public class AttrGroupController {

    @Autowired
    private AttrGroupService attrGroupService;

    @GetMapping("/all")
    public R getAllAttrGroup() {
        List<AttrGroupEntity> list = attrGroupService.list();
        return R.ok().setData(list);
    }

    /**
     * 分页获取属性分组
     * @param params
     * @return
     */
    @GetMapping("/list")
    public R getAttrGroup(@RequestParam Map<String, Object> params) {
        PageUtils pageUtils = attrGroupService.queryPage(params);
        return R.ok().setData(pageUtils);
    }

    /**
     * 根据id获取属性分组
     * @param id
     * @return
     */
    @GetMapping("/info/{id}")
    public R getAttrGroupById(@PathVariable("id") Long id) {
        AttrGroupEntity attrGroup = attrGroupService.getById(id);
        return R.ok().setData(attrGroup);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody AttrGroupEntity attrGroup){
		attrGroupService.saveAttrGroup(attrGroup);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody AttrGroupEntity attrGroup){
		attrGroupService.updateAttrGroupById(attrGroup);

        return R.ok();
    }

    @DeleteMapping("/delete/{id}")
    public R deleteAttrGroup(@PathVariable("id") Long id) {
        attrGroupService.deleteAttrGroupById(id);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] attrGroupIds) {
        attrGroupService.removeByIds(Arrays.asList(attrGroupIds));

        return R.ok();
    }


}
